import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',

    component: () => import('@/views/404'),
    hidden: true,
    meta: {
      type: "foreground",
    },
  },


  { path: '*', redirect: '/', hidden: true }
]
export const constantHomeRoutes = [

]


export const asyncRoutes = [

  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
      icon: "el-icon-s-home",
      roles: [0, 2],
    },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: {
        roles: [0, 2],
        icon: "el-icon-s-home",
        title: '控制台',
        noCache: true
      }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/Admin/UserList',
    meta: {
      title: '用户',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserList',
      component: () => import('@/views/Admin/UserList'),
      name: 'UserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/SysNotice',
    component: Layout,
    redirect: '/Admin/SysNoticeList',
    meta: {
      title: '系统通知',
      icon: "el-icon-s-tools",
      roles: [0],
    },
    children: [{
      path: 'SysNoticeList',
      component: () => import('@/views/Admin/SysNoticeList'),
      name: 'SysNoticeList',
      meta: {
        title: '系统通知',
        roles: [0],
        icon: "el-icon-s-tools",
        noCache: true
      }
    }]
  },
  {
    path: '/Banner',
    component: Layout,
    redirect: '/Admin/BannerList',
    meta: {
      title: '封面管理',
      icon: "el-icon-picture",
      roles: [0],
    },
    children: [{
      path: 'BannerList',
      component: () => import('@/views/Admin/BannerList'),
      name: 'BannerList',
      meta: {
        title: '封面',
        roles: [0],
        icon: "el-icon-picture",
        noCache: true
      }
    }]
  },
  {
    path: '/Organization',
    component: Layout,
    redirect: '/Admin/OrganizationList',
    meta: {
      title: '班级',
      icon: "el-icon-share",
      roles: [0, 2],
    },
    children: [{
      path: 'OrganizationList',
      component: () => import('@/views/Admin/OrganizationList'),
      name: 'OrganizationList',
      meta: {
        title: '班级',
        roles: [0, 2],
        icon: "el-icon-share",
        noCache: true
      }
    }, {
      path: 'OrganizationRelativeUserList',
      component: () => import('@/views/Admin/OrganizationRelativeUserList'),
      name: 'OrganizationRelativeUserList',
      meta: {
        title: '班级关联',
        roles: [0, 2],
        icon: "el-icon-s-grid",
        noCache: true
      }
    }]
  },
  {
    path: '/CheckSetting',
    component: Layout,
    redirect: '/Admin/CheckSettingList',
    meta: {
      title: '考勤设置',
      icon: "el-icon-setting",
      roles: [0, 2],
    },
    children: [{
      path: 'CheckSettingList',
      component: () => import('@/views/Admin/CheckSettingList'),
      name: 'CheckSettingList',
      meta: {
        title: '考勤设置',
        roles: [0, 2],
        icon: "el-icon-setting",
        noCache: true
      }
    }]
  },
  {
    path: '/LeaveRecord',
    component: Layout,
    redirect: '/Admin/LeaveRecordList',
    meta: {
      title: '记录',
      icon: "el-icon-s-order",
      roles: [0, 2],
    },
    children: [{
      path: 'CheckRecordList',
      component: () => import('@/views/Admin/CheckRecordList'),
      name: 'CheckRecordList',
      meta: {
        title: '打卡记录',
        roles: [0, 2],
        icon: "el-icon-s-order",
        noCache: true
      }
    }, {
      path: 'LeaveRecordList',
      component: () => import('@/views/Admin/LeaveRecordList'),
      name: 'LeaveRecordList',
      meta: {
        title: '请假记录',
        roles: [0, 2],
        icon: "el-icon-tickets",
        noCache: true
      }
    }, {
      path: 'ReCheckList',
      component: () => import('@/views/Admin/ReCheckList'),
      name: 'ReCheckList',
      meta: {
        title: '补卡记录',
        roles: [0, 2],
        icon: "el-icon-edit-outline",
        noCache: true
      }
    }]
  },
  {
    path: '/CheckRecordStatistics',
    component: Layout,
    redirect: '/Admin/CheckRecordStatistics',
    meta: {
      title: '数据分析',
      icon: "el-icon-setting",
      roles: [0, 2],
    },
    children: [{
      path: 'CheckRecordStatistics',
      component: () => import('@/views/dashboard/CheckRecordStatistics'),
      name: 'CheckRecordStatistics',
      meta: {
        title: '考勤分析',
        roles: [0, 2],
        icon: "el-icon-setting",
        noCache: true
      }
    }]
  },








]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...constantHomeRoutes, ...asyncRoutes]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
